<?php
/**
 * Created by IntelliJ IDEA.
 * User: admin
 * Date: 4/10 0010
 * Time: 9:59
 */

namespace app\api\model;


use think\Model;

/**
 * Class Applist
 * @package app\api\model
 */
class Applist extends Model
{

    public function querydetail($shopid,$appid){
        if(empty($shopid)||empty($appid)){
            return false;
        }
        $tmp=$this->where(["appid"=>$appid])->find();
        $userinfo=\model("userapp")->where(["appid"=>$appid])->where(["shopid"=>$shopid])->find();
        if(!$tmp){
            return false;
        }else{
            $appinfo=[
                "appname"=>$tmp["appname"],
                "appid"=>$tmp["appid"],
                "sprice"=>$tmp["sprice"],
                "des"=>$tmp["des"]
            ];
        }
        if($userinfo){
            $res=array_merge($appinfo,[
              "buystatus"=>(time()-$userinfo["endtime"])>0?0:1,
              "endtime"=>date("Y-m-d H:i:s",$userinfo["endtime"])
            ]);
        }else{
            $res=array_merge($appinfo,[
                "buystatus"=>-1
            ]);
        }
        return $res;
    }

    /**
     * 获取应用市场列表
     */
    public function getlist(){
        return $this->join("y_appdetail","y_appdetail.pid=y_applist.id","left")->where("status",1)->field("y_applist.id,sprice,apptype,appname,logourl")->select();
    }
}